#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cmath>
#include <cstring>

using namespace std;

class Solution
{
public:
    vector<bool> findAnswer(vector<int> &parent, string s)
    {
        int BASE = 114;
        int MOD = 1e9 + 7;
        auto ctoi = [](char c) -> int
        {
            return c - 'a' + 1;
        };

        vector<long long> products(100007);
        long long  mul = 1;
        for (int i = 0; i < 100007; i++)
        {
            products[i] = mul;
            mul = (long long)mul * BASE % MOD;
        }

        int n = parent.size();
        vector<vector<int>> g(n);
        for (int i = 1; i < n; i++)
        {
            int p = parent[i];
            g[p].push_back(i);
        }
        vector<bool> ans(n, true);
        auto dfs = [&](auto &&dfs, int root) -> tuple<int, int, int>
        {
            auto &children = g[root];
            int curPos = 0, curNev = 0, curLength = 0;
            for (auto &child : children)
            {
                auto [pos, nev, length] = dfs(dfs, child);
                curPos = (curPos + (long long)pos * products[curLength]) % MOD;
                curNev = (nev + (long long)curNev * products[length]) % MOD;
                curLength += length;
            }
            curPos = (curPos + ctoi(s[root]) * (long long)products[curLength + 1]) % MOD;
            curNev = ((curNev + ctoi(s[root])) * (long long)products[1]) % MOD;
            ans[root] = curPos == curNev;
            return {curPos, curNev, curLength + 1};
        };
        dfs(dfs, 0);
        return ans;
    }
};